package roborally.conditionCombiners;
import java.util.ArrayList;
import java.util.List;
import roborally.*;
import roborally.Conditions.*;
import roborally.Commands.*;

/**
 * A class of And-conditions for playing the roborally game, involving a list of conditions.
 * 
 * @version  2.90
 * @author   Michiel Ruelens & Dieter Naten
 */
public class And extends ConditionCombiner {
	
	private final List<Statement> conditionList;
	
	/**
	 * Creates a new combined condition 'AND' that returns true if and only if all given conditions in the list are true.
	 */
	public And(List<Statement> conditionList){
		assert(conditionList.size()>=2);
		for(Statement s: conditionList){
			assert(s instanceof Condition || s instanceof ConditionCombiner);
		}
		this.conditionList = new ArrayList<Statement>(conditionList);
		
		//Create a string representation of this conjunction
		this.setStringForm("and");
		for(Statement c: conditionList){
			this.setStringForm(this.getStringForm()+" ("+c.getStringForm()+")");
		}
	}
	
	/**
	 * Returns true if and only if all conditions in the list are true for the given robot.
	 */
	@Override
	public boolean validate(Placeable placeable){
		boolean result = true;
		for(Statement c : conditionList){
			if(c.validate(placeable)==false){
				result = false;
			}
		}
		return result;
	}
}
